import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            char[] c = in.nextLine().toCharArray();
            int len = c.length;
            // dp[i][j]表示[i,j]之间的字符串是否为回文串
            boolean[][] dp = new boolean[len][len];
            int ret = 101;
            for (int i = 0; i < len; i++) {
                for (int j = i; j >= 0; j--) {
                    if (j+1 >= i) {
                        dp[j][i] = c[j] == c[i];
                    } else {
                        dp[j][i] = c[j] == c[i] && dp[j+1][i-1];
                    }
                    if (dp[j][i] && i-j+1 != 1 && i-j+1 < ret) {
                        ret = i-j+1;
                    }
                }
            }
            System.out.println(ret == 101 ? -1 : ret);
        }
    }
}
